package com.goods.controller.business;

import com.goods.business.service.ConsumerService;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.ConsumerVO;
import com.goods.common.vo.business.SupplierVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/business/consumer")
public class ConsumerController {

    @Resource
    private ConsumerService consumerService;

    @GetMapping("/findConsumerList")
    public ResponseBean findConsumerList(Integer pageNum, Integer pageSize, String name,String address,String contact){
        Map map = consumerService.findConsumerList(pageNum,pageSize,name,address,contact);
        return ResponseBean.success(map);
    }

    @PostMapping("/add")
    public ResponseBean add(@RequestBody ConsumerVO consumerVO){
        consumerService.add(consumerVO);
        return ResponseBean.success();
    }

    @GetMapping("/edit/{id}")
    public ResponseBean edit(@PathVariable Long id){
        ConsumerVO consumerVO = consumerService.edit(id);
        return ResponseBean.success(consumerVO);
    }

    @PutMapping("/update/{id}")
    public ResponseBean update(@RequestBody ConsumerVO consumerVO){
        consumerService.update(consumerVO);
        return ResponseBean.success();
    }

    @DeleteMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable Long id){

        int num = consumerService.deleteById(id);
        if (num != 0){
            return ResponseBean.success();
        }else {
            return ResponseBean.error(num);
        }
    }
    //加载全部物资去向
    @GetMapping("/findAll")
    public ResponseBean findAll(){
        List<ConsumerVO> consumerVOList = consumerService.findAll();
        return ResponseBean.success(consumerVOList);
    }

}
